﻿using System;
using System.Collections.Generic;
using System.Windows;
using System.Linq;

using Baosight.Platform.Core.UI.Controls;
using Baosight.ZNH.ZMCA.UI.Utils;
using Telerik.Windows.Controls.Charting;
using Telerik.Windows.Controls;
using Baosight.Platform.Core;
using Baosight.Platform.Core.ServiceModel;
using Baosight.ZNH.ZMCA.UI.Controls;
using Baosight.ZNH.ZMCA.UI.Model;
using System.Reflection;
using System.Windows.Data;
using System.Windows.Media;
using System.Windows.Controls;


namespace Baosight.ZNH.ZMCA.UI
{


    public partial class ZMCA03 : EFView
    {

        ZMCA03Controler controler = new ZMCA03Controler();
        public ZMCA03()
        {
            InitializeComponent();
        }

        /// <summary>
        /// 初始化
        /// </summary>
        /// <param name="initData"></param>
        public override void Initialize(Platform.Core.EIInfo initData)
        {
            base.Initialize(initData);
            ZMCA03Controler.InitWarningPassRate(initData);

            FillCurveChartData();
            //FillGaugeData();
            //FillChartData();
            FillDayChartData();
            FillListViewData();
        }

        private void FillCurveChartData()
        {
            controler.GetCurveChartData(curveChart ,this.indexTitle);
        }

        private void FillDayChartData()
        {
            controler.GetDayChartData(this.dayChart);
        }

        private void FillListViewData()
        {
            controler.GetListViewData(lstView);
        }

        //private void FillGaugeData()
        //{
        //    controler.GetGaugeData(gauge);
        //}

        //public void FillChartData()
        //{
        //    controler.GetChartData(this.chart);
        //}
    }

    public class ZMCA03ListDataForegroundConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            double rate = Common.GetDoubleValue(value);
            double warningRate = ZMCA03Controler.MineWarningRate;
            double passRate = ZMCA03Controler.MinePassRate;

            if (parameter != null)
            {
                if (parameter.ToString().Equals("Deploitation"))
                {
                    warningRate = ZMCA03Controler.DeploitationWarningRate;
                    passRate = ZMCA03Controler.DeploitationPassRate;
                }
                else if (parameter.ToString().Equals("Grub"))
                {
                    warningRate = ZMCA03Controler.GrubWarningRate;
                    passRate = ZMCA03Controler.GrubPassRate;
                }
                else if (parameter.ToString().Equals("Hole"))
                {
                    warningRate = ZMCA03Controler.HoleWarningRate;
                    passRate = ZMCA03Controler.HolePassRate;
                }
            }
            if (rate <= warningRate)
            {
                return "Red";
            }
            else if (rate > passRate)
            {
                return "Green";
            }
            else
            {
                return "Black";
            }
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return null;
        }
    }

    public class ZMCA03Controler
    {
        public delegate void UpdateChartDateCompeleteHandler(object sender, List<ChartData> e);
        public event UpdateChartDateCompeleteHandler UpdateChartDateCompeleted;

        RadChart engChart;  //分析中心掘进进度柱状图显示
        RadChart mineChart;  //分析中心采煤进度柱状图显示
        RadChart holeChart;  //分析中心打钻进度柱状图显示
        RadChart curveChart;  //ZMCA03所有工作面的原煤产量曲线图显示
        RadChart dayChart;   //ZMCA03右侧显示日进度曲线图
        RadChart grubChart;  //ZMCA74所有工程的掘进量曲线图显示
        RadChart grubDayChart; //ZMCA74右侧显示日进度曲线图

        TriCircleGauge gauge;
        RadChart deploitChart;
        RadChart chart;
        RadTreeListView lstView;
        public bool ShowChartYearDataAndTrendLine = true;
        /// <summary>
        /// 数据所属的年份信息
        /// 默认查找当年的数据，当设置了这个值则按PlanYear进行查找，并且找到的数据是1到12月的。
        /// </summary>
        public string PlanYear
        {
            get;
            set;
        }

        public static double HoleWarningRate = 0.8;
        public static double HolePassRate = 1.0;
        public static double MineWarningRate = 0.8;
        public static double MinePassRate = 1.0;
        public static double GrubWarningRate = 0.8;
        public static double GrubPassRate = 1.0;
        public static double DeploitationWarningRate = 0.8;
        public static double DeploitationPassRate = 1.0;
        static double maxValueRate = 1.5;


        public static void InitWarningPassRate(EIInfo initData)
        {
            EIBlock configBlock = initData.GetBlock("cmes.ca.config");
            //MineWarningRate = Common.GetDoubleValue(configBlock.GetRow(0)["fdRemarks"]);
            //MinePassRate = Common.GetDoubleValue(configBlock.GetRow(1)["fdRemarks"]);
            //GrubWarningRate = Common.GetDoubleValue(configBlock.GetRow(2)["fdRemarks"]);
            //GrubPassRate = Common.GetDoubleValue(configBlock.GetRow(3)["fdRemarks"]);
            //DeploitationWarningRate = Common.GetDoubleValue(configBlock.GetRow(4)["fdRemarks"]);
            //DeploitationPassRate = Common.GetDoubleValue(configBlock.GetRow(5)["fdRemarks"]);

            string fdKeyColumnName = "fdSerialNumber";
            string fdValueColumnName = "fdRemarks";
            MineWarningRate = GetConfig(configBlock, "1", fdKeyColumnName, fdValueColumnName);
            MinePassRate = GetConfig(configBlock, "2", fdKeyColumnName, fdValueColumnName);
            GrubWarningRate = GetConfig(configBlock, "3", fdKeyColumnName, fdValueColumnName);
            GrubPassRate = GetConfig(configBlock, "4", fdKeyColumnName, fdValueColumnName);
            DeploitationWarningRate = GetConfig(configBlock, "5", fdKeyColumnName, fdValueColumnName);
            DeploitationPassRate = GetConfig(configBlock, "6", fdKeyColumnName, fdValueColumnName);
            HoleWarningRate = GetConfig(configBlock, "20", fdKeyColumnName, fdValueColumnName);// Common.GetDoubleValue(configBlock.GetRow(0)["fdRemarks"]);
            HolePassRate = GetConfig(configBlock, "21", fdKeyColumnName, fdValueColumnName); //Common.GetDoubleValue(configBlock.GetRow(1)["fdRemarks"]);

        }


        public static double GetConfig(EIBlock config, string index, string fdKeyColumnName, string fdValueColumnName)
        {
            var result = from item in config.Rows where item[fdKeyColumnName].ToString().Trim() == index select item[fdValueColumnName].ToString();
            string val = result.ElementAtOrDefault(0).Trim();

            if (val != null || (!"".Equals(val.Trim())))
                return Common.GetDoubleValue(val);
            else
                return 1;
        }

        public string PlanType
        {
            get;
            set;
        }
        /// <summary>
        /// 当IsDeploitation不为空时，查询开拓数据
        /// </summary>
        public string IsDeploitation
        {
            get;
            set;
        }
        public ZMCA03Controler()
        {
            PlanType = "采煤计划";
            IsDeploitation = string.Empty;
            PlanYear = string.Empty;
        }

        #region 获取刷新Gauge图数据

        public void GetGaugeData(TriCircleGauge gauge)
        {
            this.gauge = gauge;

            gauge.gaugeTitle.Text = "原煤产量";
            if (IsDeploitation != string.Empty)
            {
                gauge.gaugeTitle.Text = "开拓进尺";
            }
            else if (PlanType != "采煤计划")
            {
                gauge.gaugeTitle.Text = "综合进尺";
            }

            EIInfo eiInfo = new EIInfo();
            eiInfo.Set("service", "ZMCA03");
            eiInfo.Set("method", "queryByIndex");
            eiInfo.Set("PlanType", PlanType);
            eiInfo.Set("IsDeploitation", IsDeploitation);

            HttpServiceAgent agent = new HttpServiceAgent();
            agent.CallService(eiInfo, getGaugeDataCompleted);
        }

        private void getGaugeDataCompleted(object sender, DoWorkCompletedEventArgs e)
        {
            if (e.EIInfo.Status == -1)
            {
                Common.Alert(Common.MsgLoadDataError);
                return;
            }
            EIInfo eiInfo = e.EIInfo;
            EIBlock result = eiInfo.GetBlock("result");

            int dayOfYear = Common.GetIntValue(eiInfo.Get("dayOfYear"));
            int dayOfMonth = Common.GetIntValue(eiInfo.Get("dayOfMonth"));
            int daysOfCurrentMonth = Common.GetIntValue(eiInfo.Get("daysOfCurrentMonth"));
            int currentYear = Common.GetIntValue(eiInfo.Get("year"));
            int daysOfCurrentYear = DateTime.IsLeapYear(currentYear) ? 366 : 365;

            double yearPlan = 0;
            double yearActual = 0;
            double monthPlan = 0;
            double monthAcutal = 0;
            double dayPlan = 0;
            double dayActual = 0;
            if (result != null && result.Rows.Count > 0)
            {
                foreach (var item in result.Rows)
                {
                    int dataType = Common.GetIntValue(item["fdPlanType"]);
                    //通过dataType判断数据类型,0年计划， 1月计划，20年实际， 30月实际， 35昨日计划， 40昨日
                    if (dataType == 0)
                    {
                        yearPlan = Common.GetDoubleValue(item["fdPlanMine"]);
                    }
                    else if (dataType < 20)
                    {
                        monthPlan = Common.GetDoubleValue(item["fdPlanMine"]);
                    }
                    else if (dataType == 20)
                    {
                        yearActual = Common.GetDoubleValue(item["fdPlanMine"]);
                    }
                    else if (dataType == 30)
                    {
                        monthAcutal = Common.GetDoubleValue(item["fdPlanMine"]);
                    }
                    else if (dataType == 35)
                    {
                        dayPlan = Common.GetDoubleValue(item["fdPlanMine"]);
                    }
                    else if (dataType == 40)
                    {
                        dayActual = Common.GetDoubleValue(item["fdPlanMine"]);
                    }
                }
            }

            //将年计划和月计划变为到今天为止的计划量
            //年计划量 = 日均年度计划量×当年至昨日天数
            //月计划量 = 当月的日均月计划量×当月至昨日天数

            monthPlan = monthPlan * dayOfMonth / daysOfCurrentMonth;
            yearPlan = yearPlan * dayOfYear / daysOfCurrentYear;

            //计算单位，并将指标值缩小到100以内
            int dayUnit = GetUnit(dayPlan);
            int monthUnit = GetUnit(monthPlan);
            int yearUnit = GetUnit(yearPlan);

            if (dayActual > dayPlan)
            {
                dayUnit = GetUnit(dayActual);
            }
            if (monthAcutal > monthPlan)
            {
                monthUnit = GetUnit(monthAcutal);
            }
            if (yearActual > yearPlan)
            {
                yearUnit = GetUnit(yearActual);
            }

            dayPlan = dayPlan / dayUnit;
            monthPlan = monthPlan / monthUnit;
            yearPlan = yearPlan / yearUnit;

            dayActual = dayActual / dayUnit;
            monthAcutal = monthAcutal / monthUnit;
            yearActual = yearActual / yearUnit;

            //设置最大值
            
            gauge.leftControler.SetMaxValue(dayPlan * maxValueRate);
            gauge.centerControler.SetMaxValue(yearPlan * maxValueRate);
            gauge.rightControler.SetMaxValue(monthPlan * maxValueRate);
            //设置指标盘的预警值
            double warningRate = MineWarningRate;
            double passRate = MinePassRate;
            string unit = "吨";
            if (IsDeploitation != string.Empty)
            {
                unit = "米";
                warningRate = DeploitationWarningRate;
                passRate = DeploitationPassRate;
            }
            else if (PlanType != "采煤计划")
            {
                unit = "米";
                warningRate = GrubWarningRate;
                passRate = GrubPassRate;
            }


            gauge.leftControler.SetMarkerValer(dayPlan * warningRate, dayPlan * passRate);
            gauge.centerControler.SetMarkerValer(yearPlan * warningRate, yearPlan * passRate);
            gauge.rightControler.SetMarkerValer(monthPlan * warningRate, monthPlan * passRate);

            gauge.leftGaugeDescription.Text = dayUnit >= 10 ? Common.GetChineseUnit(dayUnit) + unit + "/日" : unit + "/日";
            gauge.centerGaugeDescription.Text = yearUnit >= 10 ? Common.GetChineseUnit(yearUnit) + unit + "/年" : unit + "/年";
            gauge.rightGaugeDescription.Text = monthUnit >= 10 ? Common.GetChineseUnit(monthUnit) + unit + "/月" : unit + "/月";

            gauge.leftAdditionalInfo.Text = Common.GetPercentText(dayActual, dayPlan);
            gauge.leftAdditionalInfo.Visibility = Visibility.Visible;
            gauge.centerAdditionalInfo.Text = Common.GetPercentText(yearActual, yearPlan);
            gauge.centerAdditionalInfo.Visibility = Visibility.Visible;
            gauge.rightAdditionalInfo.Text = Common.GetPercentText(monthAcutal, monthPlan);
            gauge.rightAdditionalInfo.Visibility = Visibility.Visible;

            gauge.leftNeedle.Value = dayActual;
            gauge.centerNeedle.Value = yearActual;
            gauge.rightNeedle.Value = monthAcutal;

        }

        public static int GetUnit(double value)
        {
            int unit = 1;
            while (value > 100 * unit)
            {
                unit *= 10;
            }
            return unit;
        }

        #endregion

        public void GetChartData(RadChart chart)
        {
            this.chart = chart;

            EIInfo eiInfo = new EIInfo();
            eiInfo.Set("service", "ZMCA03");
            eiInfo.Set("method", "queryByChart");
            eiInfo.Set("PlanType", PlanType);
            eiInfo.Set("PlanYear", PlanYear);
            eiInfo.Set("IsDeploitation", IsDeploitation);

            HttpServiceAgent agent = new HttpServiceAgent();
            agent.CallService(eiInfo, getChartDataCompleted);
        }

        private void getChartDataCompleted(object sender, DoWorkCompletedEventArgs e)
        {
            if (e.EIInfo.Status == -1)
            {
                Common.Alert(Common.MsgLoadDataError);
                return;
            }

            EIInfo eiInfo = e.EIInfo;
            EIBlock queryByChart = eiInfo.GetBlock("queryByChart");
            int currentMonth = Common.GetIntValue(eiInfo.Get("month"));
            int currentYear = Common.GetIntValue(eiInfo.Get("year"));
            if (PlanYear != string.Empty)
            {
                currentYear = Common.GetIntValue(PlanYear);
                currentMonth = 12;
            }

            chart.SeriesMappings.Clear();
            //chart.DefaultView.ChartTitle.Content = currentYear + "趋势分析";
            chart.DefaultSeriesDefinition.ShowItemToolTips = true;
            chart.DefaultSeriesDefinition.LegendDisplayMode = LegendDisplayMode.DataPointLabel;
            chart.DefaultView.ChartLegend.Header = string.Empty;
            chart.DefaultView.ChartLegendPosition = Telerik.Windows.Controls.Dock.Bottom;

            this.chart.DefaultView.ChartArea.AxisY.MajorGridLinesVisibility = Visibility.Visible;
            this.chart.DefaultView.ChartArea.AxisY.MinorGridLinesVisibility = Visibility.Visible;
            this.chart.DefaultView.ChartArea.AxisY.StripLinesVisibility = Visibility.Visible;

            this.chart.DefaultView.ChartTitle.FontSize = Common.FontsizeSetting + 2;
            this.chart.DefaultView.ChartArea.FontSize = Common.FontsizeSetting;
            this.chart.DefaultView.ChartLegend.FontSize = Common.FontsizeSetting - 2;
            this.chart.DefaultView.ChartArea.AxisY.DefaultLabelFormat = Common.HomePageChartItemLabelFormat;

            string unit = "吨";
            if (PlanType != "采煤计划")
            {
                unit = "米";
            }

            //In fact add new SplineSeriesDefinition to chart 
            SeriesMapping sm1 = Common.GenerateSeriesForChart("计划", 0, "Spline", "PlanValue");
            SeriesMapping sm2 = Common.GenerateSeriesForChart("实际", 0, "Spline");
            sm1.SeriesDefinition.ItemLabelFormat = Common.ChartDefaultLabelFormat;
            sm2.SeriesDefinition.ItemLabelFormat = Common.ChartDefaultLabelFormat;
            chart.SeriesMappings.Add(sm1);
            chart.SeriesMappings.Add(sm2);

            //StackPanel spLegendHeader = new StackPanel();
            //spLegendHeader.Orientation = Orientation.Horizontal;
            //TextBlock tbLegendHeader = new TextBlock();
            //tbLegendHeader.Text = currentYear + "趋势分析";
            //tbLegendHeader.Foreground = new SolidColorBrush(Colors.White);
            //spLegendHeader.Children.Add(tbLegendHeader);
            //if (ShowChartYearDataAndTrendLine)
            //{
            //    //ShowLineSerie();
            //    //使tbLegendHeader.Text位于正中央
            //    TextBlock tbForAlignment = new TextBlock();
            //    tbForAlignment.Width = 120;
            //    spLegendHeader.Children.Insert(0, tbForAlignment);

            //    TextBlock tbEmpty = new TextBlock();
            //    tbEmpty.Width = 20;
            //    spLegendHeader.Children.Add(tbEmpty);

            //    EFCheckBox cbShowLineSerie = new EFCheckBox();
            //    cbShowLineSerie.Content = "显示趋势线";
            //    cbShowLineSerie.Width = 100.0;
            //    cbShowLineSerie.Foreground = new SolidColorBrush(Colors.White);
            //    cbShowLineSerie.Checked += new RoutedEventHandler(cbShowLineSerie_Checked);
            //    cbShowLineSerie.Unchecked += new RoutedEventHandler(cbShowLineSerie_Unchecked);
            //    spLegendHeader.Children.Add(cbShowLineSerie);

            //}
            //chart.DefaultView.ChartTitle.Content = spLegendHeader;
            //chart.DefaultView.ChartLegend.Header = "单位：" + unit; ;


            List<List<ChartData>> itemsSource = new List<List<ChartData>>();
            List<ChartData> lstData = new List<ChartData>();
            List<ChartData> lstRate = new List<ChartData>();

            for (int i = 1; i <= currentMonth; i++)
            {
                lstData.Add(new ChartData(i + "月", 0));
                lstRate.Add(new ChartData(i + "月", 0));
            }
            //if (ShowChartYearDataAndTrendLine)
            //{
            //    lstData.Add(new ChartData("全年", 0));
            //}
            //lstPlan.Add(new ChartData(" ", 0));
            //lstRate.Add(new ChartData("全年", 0));

            //fdPlanType: 0年计划， 1月计划，20年实际， 30月实际， 40昨日
            foreach (var item in queryByChart.Rows)
            {
                if (item["fdPlanYear"].ToString().Trim() == string.Empty)
                {
                    continue;
                }
                int dataType = Common.GetIntValue(item["fdPlanType"]);
                int month = Common.GetIntValue(item["fdPlanMonth"]);
                if (month == 0)
                {
                    //if (ShowChartYearDataAndTrendLine)
                    //{
                    //    lstData[lstData.Count - 1].PlanValue = Common.GetDecimalValue(item["fdPlanMine"]);
                    //    lstData[lstData.Count - 1].DataValue = Common.GetDecimalValue(item["fdActualSum"]);
                    //}
                }
                else if (month <= currentMonth)
                {
                    lstData[month - 1].PlanValue = Common.GetDecimalValue(item["fdPlanMine"]);
                    lstData[month - 1].DataValue = Common.GetDecimalValue(item["fdActualSum"]);
                }

            }
            itemsSource.Add(lstData);

            if (ShowChartYearDataAndTrendLine)
            {
                for (int i = 0; i < lstRate.Count; i++)
                {
                    lstRate[i].DataValue = Common.GetPercent(lstData[i].DataValue, lstData[i].PlanValue);
                }
                itemsSource.Add(lstRate);
            }

            chart.ItemsSource = itemsSource;
            if (UpdateChartDateCompeleted != null)
            {
                UpdateChartDateCompeleted(sender, lstData);
            }
        }

        void cbShowLineSerie_Unchecked(object sender, RoutedEventArgs e)
        {
            chart.DefaultView.ChartArea.AdditionalYAxes.Clear();
            chart.SeriesMappings.RemoveAt(chart.SeriesMappings.Count - 1);
        }

        private void ShowLineSerie()
        {
            chart.DefaultView.ChartArea.AdditionalYAxes.Clear();
            chart.DefaultView.ChartArea.AdditionalYAxes.Add(new AxisY());
            chart.DefaultView.ChartArea.AdditionalYAxes[0].AxisName = "Secondary";
            chart.DefaultView.ChartArea.AdditionalYAxes[0].DefaultLabelFormat = "P";

            SeriesMapping sm3 = Common.AddPercentageSplineToChart("完成率", 1);
            chart.SeriesMappings.Add(sm3);
        }

        void cbShowLineSerie_Checked(object sender, RoutedEventArgs e)
        {
            ShowLineSerie();
        }


        #region 获取刷新RadListView数据

        public void GetListViewData(RadTreeListView lstView)
        {
            this.lstView = lstView;
            EIInfo eiInfo = new EIInfo();
            eiInfo.Set("service", "ZMCA03");
            eiInfo.Set("method", "queryByListView");
            eiInfo.Set("PlanType", PlanType);
            eiInfo.Set("IsDeploitation", IsDeploitation);

            HttpServiceAgent agent = new HttpServiceAgent();
            agent.CallService(eiInfo, getListViewDataCompleted);
        }

        private void getListViewDataCompleted(object sender, DoWorkCompletedEventArgs e)
        {
            if (e.EIInfo.Status == -1)
            {
                Common.Alert(Common.MsgLoadDataError);
                return;
            }

            EIInfo eiInfo = e.EIInfo;

            int currentMonth = Common.GetIntValue(eiInfo.Get("month"));
            int currentYear = Common.GetIntValue(eiInfo.Get("year"));

            for (int i = 12 - currentMonth + 2; i > 2; i--)
            {
                var cl = lstView.Columns[i];
                cl.IsVisible = false;
            }

            List<ZMCA03DetailItem> itemsSource = new List<ZMCA03DetailItem>();
            ZMCA03DetailItem yearItem = new ZMCA03DetailItem();

            itemsSource.Add(yearItem);
            Type itemType = yearItem.GetType();
            yearItem.Name = "全矿";


            //queryByWorkFace工作面汇总计划量，queryByWorkFaceA工作面汇总实际量
            //queryByDepartment单位汇总计划量，queryByDepartmentA单位汇总实际量

            if (PlanType.Equals("采煤计划"))
            {
                EIBlock queryByWorkFace = eiInfo.GetBlock("queryByWorkFace");
                EIBlock queryByWorkFaceA = eiInfo.GetBlock("queryByWorkFaceA");
                ZMCA03DetailItem yearWorkFaceItem = new ZMCA03DetailItem();
                yearWorkFaceItem.Name = "所有工作面";
                yearItem.Items.Add(yearWorkFaceItem);
                AddChildItemByBlock(queryByWorkFace, queryByWorkFaceA, yearWorkFaceItem, itemType, "fdWorkface");
                yearItem.CopyData(yearWorkFaceItem);
            }
            else
            {
                //对于掘进和开拓的情况，巷道用途名称、巷道名称和煤岩类别都保存在fdWorkface属性中
                //对于采掘，要多查一下巷道类别
                if (IsDeploitation.Trim().Length <= 0)
                {
                    //EIBlock queryByRoadWayUsing = eiInfo.GetBlock("queryByRoadWayUsing");
                    //EIBlock queryByRoadWayUsingA = eiInfo.GetBlock("queryByRoadWayUsingA");
                    EIBlock queryByEngineeringClass = eiInfo.GetBlock("ProjectClass");
                    ZMCA03DetailItem yearEngineeringClassItem = new ZMCA03DetailItem();
                    yearEngineeringClassItem.Name = "所有工程类别";
                    yearItem.Items.Add(yearEngineeringClassItem);
                    AddChildItems(queryByEngineeringClass, yearEngineeringClassItem, itemType, "fdProjectId");
                    //AddChildItemByBlock(queryByRoadWayUsing, queryByRoadWayUsingA, yearRoadWayUsingItem, itemType, "fdWorkface");
                }
                //EIBlock queryByRoadWay = eiInfo.GetBlock("queryByRoadWay");
                //EIBlock queryByRoadWayA = eiInfo.GetBlock("queryByRoadWayA");
                //ZMCA03DetailItem yearRoadWayItem = new ZMCA03DetailItem();
                //yearRoadWayItem.Name = "所有巷道";
                //yearItem.Items.Add(yearRoadWayItem);
                //AddChildItemByBlock(queryByRoadWay, queryByRoadWayA, yearRoadWayItem, itemType, "fdWorkface");

                EIBlock queryByMineRock = eiInfo.GetBlock("queryByMineRock");
                EIBlock queryByMineRockA = eiInfo.GetBlock("queryByMineRockA");
                ZMCA03DetailItem yearMineRockItem = new ZMCA03DetailItem();
                yearMineRockItem.Name = "所有煤岩类别";
                yearItem.Items.Add(yearMineRockItem);
                AddChildItemByBlock(queryByMineRock, queryByMineRockA, yearMineRockItem, itemType, "fdWorkface");
                yearItem.CopyData(yearMineRockItem);
            }


            ZMCA03DetailItem yearDepartmentItem = new ZMCA03DetailItem();
            yearDepartmentItem.Name = "所有单位";
            yearItem.Items.Add(yearDepartmentItem);
            EIBlock queryByDepartment = eiInfo.GetBlock("queryByDepartment");
            EIBlock queryByDepartmentA = eiInfo.GetBlock("queryByDepartmentA");
            AddDepartmentChildItemByBlock(queryByDepartment, queryByDepartmentA, yearDepartmentItem, itemType);

            lstView.ItemsSource = itemsSource;
        }

        /// <summary>
        /// 构造单位汇总数据，逻辑类似ZMCA12
        /// </summary>
        /// <param name="block"></param>
        /// <param name="blockR"></param>
        /// <param name="parentDetailItem"></param>
        /// <param name="itemType"></param>
        public static void AddDepartmentChildItemByBlock(EIBlock block, EIBlock blockR, ZMCA03DetailItem parentDetailItem, Type itemType)
        {
            Dictionary<string, ZMCA03DetailItem> dic = new Dictionary<string, ZMCA03DetailItem>();
            ZMCA03DetailItem detailItem = null;
            foreach (var item in block.Rows)
            {
                string year = Common.GetStringValue(item["fdPlanYear"]);
                string month = Common.GetStringValue(item["fdPlanMonth"]);

                string itemUniqueName = Common.GetStringValue(item["fdDepartmentId"]);
                if (detailItem == null || detailItem.UniqueName != itemUniqueName)
                {
                    detailItem = new ZMCA03DetailItem();
                    dic.Add(itemUniqueName, detailItem);
                    if (Common.GetIntValue(item["fdDepartmentLevel"]) == 1)
                    {
                        parentDetailItem.Items.Add(detailItem);
                    }
                    else
                    {
                        if (dic.ContainsKey(item["fdParentDepartmentId"].ToString()))
                        {
                            dic[item["fdParentDepartmentId"].ToString()].Items.Add(detailItem);
                        }
                        else
                        {
                            parentDetailItem.Items.Add(detailItem);
                            //单位层级有问题，找不到父亲单位
                        }
                    }
                    detailItem.UniqueName = itemUniqueName;

                    detailItem.Name = item["fdDepartmentName"].ToString();
                }

                if (year == string.Empty)
                {
                    continue;
                }

                PropertyInfo pi = itemType.GetProperty("M" + month);
                pi.SetValue(detailItem, Common.GetDecimalValue(item["fdPlanMine"]), null);
            }

            foreach (var item in blockR.Rows)
            {
                string year = Common.GetStringValue(item["fdPlanYear"]);
                string month = Common.GetStringValue(item["fdPlanMonth"]);

                string itemUniqueName = Common.GetStringValue(item["fdDepartmentId"]);
                if (!dic.ContainsKey(itemUniqueName))
                {
                    detailItem = new ZMCA03DetailItem();
                    detailItem.UniqueName = itemUniqueName;
                    detailItem.Name = item["fdDepartmentName"].ToString();
                    dic.Add(itemUniqueName, detailItem);
                    parentDetailItem.Items.Add(detailItem);
                }
                detailItem = dic[itemUniqueName];

                if (year == string.Empty)
                {
                    continue;
                }
                else if (month.Trim() == "0")
                {
                    detailItem.Yesterday = Common.GetDecimalValue(item["fdPlanMine"]);
                    continue;
                }
                else if (month[0] == '0')//有时月份以09形式出现，需将前面0却掉
                {
                    month = month.Substring(1, 1);
                }

                PropertyInfo pi_Revise = itemType.GetProperty("M" + month + "_Revise");
                pi_Revise.SetValue(detailItem, Common.GetDecimalValue(item["fdPlanMine"]), null);
            }

            ZMCA03DetailItem.SummarizedChildItemData(parentDetailItem);
        }

        public static void AddChildItemByBlock(EIBlock block, EIBlock blockR, ZMCA03DetailItem parentDetailItem, Type itemType, string UniqueColumnName)
        {
            AddChildItemByBlock(block, blockR, parentDetailItem, itemType, UniqueColumnName, UniqueColumnName);
        }

        public static void AddChildItemByBlock(EIBlock block, EIBlock blockR, ZMCA03DetailItem parentDetailItem, Type itemType, string UniqueColumnName, string ItemName)
        {

            ZMCA03DetailItem detailItem = null;
            Dictionary<string, ZMCA03DetailItem> dic = new Dictionary<string, ZMCA03DetailItem>();
            foreach (var item in block.Rows)
            {
                string year = item["fdPlanYear"].ToString();
                if (year.Trim() == string.Empty)
                {
                    continue;
                }
                string month = item["fdPlanMonth"].ToString();
                string itemUniqueName = Common.GetStringValue(item[UniqueColumnName]);
                if (detailItem == null || detailItem.UniqueName != itemUniqueName)
                {
                    detailItem = new ZMCA03DetailItem();
                    parentDetailItem.Items.Add(detailItem);
                    detailItem.UniqueName = itemUniqueName;
                    detailItem.Name = Common.GetStringValue(item[ItemName]);
                    dic.Add(itemUniqueName, detailItem);
                }

                PropertyInfo pi = itemType.GetProperty("M" + month);
                pi.SetValue(detailItem, Common.GetDecimalValue(item["fdPlanMine"]), null);
            }

            foreach (var item in blockR.Rows)
            {
                string year = item["fdPlanYear"].ToString();
                if (year.Trim() == string.Empty)
                {
                    continue;
                }
                string month = item["fdPlanMonth"].ToString();

                //Service16中的实际值的月份是用MM形式，需要把前面的0去掉
                if (month.Length == 2 && month[0] == '0')
                {
                    month = month.Substring(1, 1);
                }

                string itemUniqueName = Common.GetStringValue(item[UniqueColumnName]);

                //实际有的计划可能没有

                if (!dic.ContainsKey(itemUniqueName))
                {
                    detailItem = new ZMCA03DetailItem();
                    parentDetailItem.Items.Add(detailItem);
                    detailItem.UniqueName = itemUniqueName;
                    detailItem.Name = Common.GetStringValue(item[ItemName]);
                    dic.Add(itemUniqueName, detailItem);
                }


                detailItem = dic[itemUniqueName];

                if (month.Trim() == "0")
                {
                    detailItem.Yesterday = Common.GetDecimalValue(item["fdPlanMine"]);
                    continue;
                }

                PropertyInfo pi_Revise = itemType.GetProperty("M" + month + "_Revise");
                pi_Revise.SetValue(detailItem, Common.GetDecimalValue(item["fdPlanMine"]), null);
            }
            ZMCA03DetailItem.SummarizedChildItemData(parentDetailItem);
        }

        public void AddChildItems(EIBlock block, ZMCA03DetailItem parentDetailItem, Type itemType, string UniqueColumnName)
        {
            Dictionary<string, ZMCA03DetailItem> dic = new Dictionary<string, ZMCA03DetailItem>();
            ZMCA03DetailItem detailItem = null;
            foreach (var item in block.Rows)
            {
                string year = Common.GetStringValue(item["fdPlanYear"]);
                string month = Common.GetStringValue(item["fdPlanMonth"]);

                string itemUniqueName = Common.GetStringValue(item[UniqueColumnName]);
                if (detailItem == null || detailItem.UniqueName != itemUniqueName)
                {
                    detailItem = new ZMCA03DetailItem();
                    parentDetailItem.Items.Add(detailItem);
                    detailItem.UniqueName = itemUniqueName;
                    detailItem.Name = Common.GetStringValue(item[UniqueColumnName]);
                    dic.Add(itemUniqueName, detailItem);
                }

                if (year == string.Empty)
                {
                    continue;
                }

                if (month != "0")
                {
                    PropertyInfo pi = itemType.GetProperty("M" + month);
                    pi.SetValue(detailItem, Common.GetDecimalValue(item["fdPlanMine"]), null);
                    PropertyInfo pi_Revise = itemType.GetProperty("M" + month + "_Revise");
                    pi_Revise.SetValue(detailItem, Common.GetDecimalValue(item["fdActualSum"]), null);
                }
                else
                {
                    detailItem.Yesterday = Common.GetDecimalValue(item["fdActualSum"]);
                }
            }

            ZMCA03DetailItem.SummarizedChildItemData(parentDetailItem);
        }





        #endregion

        #region 分析中心掘进工程进度柱状图

        public void GetEngineeringChartData(RadChart chart ,string type)
        {
            string serviceName = "ZMCA03";
            string methodName = "queryEngByChart";

            if (type.Equals("0"))
                this.mineChart = chart;
            else if (type.Equals("1"))
                this.engChart = chart;
            else if (type.Equals("2"))
            {
                this.holeChart = chart;
                serviceName = "ZMCA16";
                methodName = "queryWorkfaceByChart";
            }
            EIInfo eiInfo = new EIInfo();
            eiInfo.SetDesc(type);
            eiInfo.Set("service", serviceName);

            eiInfo.Set("method", methodName);

            HttpServiceAgent agent = new HttpServiceAgent();
            agent.CallService(eiInfo, GetEngineeringChartDataCompleted);
        }


        private void GetEngineeringChartDataCompleted(object sender, DoWorkCompletedEventArgs e)
        {
            if (e.EIInfo.Status == -1)
            {
                Common.Alert(Common.MsgLoadDataError);
                return;
            }

            EIBlock result = e.EIInfo.GetBlock("result");
            int currentMonth = Common.GetIntValue(e.EIInfo.Get("month"));
            int currentYear = Common.GetIntValue(e.EIInfo.Get("year"));
            string type = e.EIInfo.GetDesc();

            RadChart c = this.mineChart;
            if (type.Equals("1"))
                c = this.engChart;
            else if (type.Equals("2"))
                c = this.holeChart;

            c.DefaultView.ChartTitle.FontSize = 14;
            c.DefaultView.ChartArea.FontSize = 10;
            c.DefaultView.ChartLegend.FontSize = 10;
            if (e.EIInfo.GetDesc().Equals("0"))
            {
                //c.DefaultView.ChartTitle.Content = currentMonth + "月采煤工程进度";
                c.DefaultView.ChartLegend.Header = "单位：吨";

            }
            else if (e.EIInfo.GetDesc().Equals("1"))
            {
                //c.DefaultView.ChartTitle.Content = currentMonth + "月掘进工程进度"
                c.DefaultView.ChartLegend.Header = "单位：米";
            }
            else if (e.EIInfo.GetDesc().Equals("2"))
            {
                //c.DefaultView.ChartTitle.Content = currentMonth + "月掘进工程进度"
                c.DefaultView.ChartLegend.Header = "单位：米";
            }

            c.DefaultView.ChartTitle.Visibility = Visibility.Collapsed;

            c.DefaultSeriesDefinition.ShowItemToolTips = true;
            c.DefaultSeriesDefinition.LegendDisplayMode = LegendDisplayMode.DataPointLabel;
            c.DefaultView.ChartArea.AxisY.AutoRange = true;
            c.DefaultView.ChartArea.AxisY.DefaultLabelFormat = "#VAL ";
            c.DefaultView.ChartArea.AxisY.MajorGridLinesVisibility = Visibility.Visible;
            c.DefaultView.ChartArea.AxisY.MinorGridLinesVisibility = Visibility.Visible;
            c.DefaultView.ChartArea.AxisY.StripLinesVisibility = Visibility.Visible;
            c.DefaultView.ChartLegendPosition = Telerik.Windows.Controls.Dock.Bottom;
            c.DefaultView.ChartArea.AxisY.DefaultLabelFormat = Common.ChartDefaultLabelFormat;

            c.SeriesMappings.Add(Common.GenerateSeriesForChart("计划", 0, "Spline"));
            c.SeriesMappings.Add(Common.GenerateSeriesForChart("实际", 1, "Spline"));

            List<List<ChartData>> chartItemsSource = new List<List<ChartData>>();
            List<ChartData> lstActual = new List<ChartData>();
            List<ChartData> lstPlan = new List<ChartData>();
            foreach (var item in result.Rows)
            {
                lstPlan.Add(new ChartData(Common.GetStringValue(item["fdProjectName"]),
                    Common.GetDecimalValue(item["fdPlanGrub"])));
                lstActual.Add(new ChartData(Common.GetStringValue(item["fdProjectName"]),
                    Common.GetDecimalValue(item["fdActualSum"])));
            }

            chartItemsSource.Add(lstPlan);
            chartItemsSource.Add(lstActual);
            c.ItemsSource = null;
            c.ItemsSource = chartItemsSource;
        }

        #endregion

        #region 开拓进尺柱状图

        public void GetDeploitChartData(RadChart c)
        {
            this.deploitChart = c;

            EIInfo eiInfo = new EIInfo();
            eiInfo.Set("service", "ZMCA03");
            eiInfo.Set("method", "queryByChart");
            eiInfo.Set("PlanType", PlanType);
            eiInfo.Set("PlanYear", PlanYear);
            eiInfo.Set("IsDeploitation", IsDeploitation);

            HttpServiceAgent agent = new HttpServiceAgent();
            agent.CallService(eiInfo, getDeploitChartDataCompleted);
        }

        private void getDeploitChartDataCompleted(object sender, DoWorkCompletedEventArgs e)
        {
            if (e.EIInfo.Status == -1)
            {
                Common.Alert(Common.MsgLoadDataError);
                return;
            }

            EIInfo eiInfo = e.EIInfo;
            EIBlock queryBydeploitChart = eiInfo.GetBlock("queryByChart");
            int currentMonth = Common.GetIntValue(eiInfo.Get("month"));
            int currentYear = Common.GetIntValue(eiInfo.Get("year"));
            if (PlanYear != string.Empty)
            {
                currentYear = Common.GetIntValue(PlanYear);
                currentMonth = 12;
            }

            deploitChart.SeriesMappings.Clear();
            //deploitChart.DefaultView.deploitChartTitle.Content = currentYear + "趋势分析";
            deploitChart.DefaultSeriesDefinition.ShowItemToolTips = true;
            deploitChart.DefaultSeriesDefinition.LegendDisplayMode = LegendDisplayMode.DataPointLabel;
            //deploitChart.DefaultView.deploitChartLegend.Header = string.Empty;
            this.deploitChart.DefaultView.ChartArea.AxisY.MajorGridLinesVisibility = Visibility.Visible;
            this.deploitChart.DefaultView.ChartArea.AxisY.MinorGridLinesVisibility = Visibility.Visible;
            this.deploitChart.DefaultView.ChartArea.AxisY.StripLinesVisibility = Visibility.Visible;
            this.deploitChart.DefaultView.ChartArea.AxisY.DefaultLabelFormat = Common.ChartDefaultLabelFormat;

            string unit = "吨";
            if (PlanType != "采煤计划")
            {
                unit = "米";
            }
            SeriesMapping sm1 = Common.GenerateSeriesForChart("计划", 0, "Spline", "PlanValue");
            SeriesMapping sm2 = Common.GenerateSeriesForChart("实际", 0, "Spline");
            sm1.SeriesDefinition.ItemLabelFormat = Common.ChartDefaultLabelFormat;
            sm2.SeriesDefinition.ItemLabelFormat = Common.ChartDefaultLabelFormat;
            deploitChart.SeriesMappings.Add(sm1);
            deploitChart.SeriesMappings.Add(sm2);

            //StackPanel spLegendHeader = new StackPanel();
            //spLegendHeader.Orientation = Orientation.Horizontal;
            //TextBlock tbLegendHeader = new TextBlock();
            //tbLegendHeader.Text = currentYear + "趋势分析";
            //tbLegendHeader.Foreground = new SolidColorBrush(Colors.White);
            //spLegendHeader.Children.Add(tbLegendHeader);

            deploitChart.DefaultView.ChartTitle.Visibility = Visibility.Collapsed;
            deploitChart.DefaultView.ChartLegend.Header = "单位：" + unit; ;


            List<List<ChartData>> itemsSource = new List<List<ChartData>>();
            List<ChartData> lstData = new List<ChartData>();
            List<ChartData> lstRate = new List<ChartData>();

            for (int i = 1; i <= currentMonth; i++)
            {
                lstData.Add(new ChartData(i + "月", 0));
                lstRate.Add(new ChartData(i + "月", 0));
            }

            //lstPlan.Add(new deploitChartData(" ", 0));
            //lstRate.Add(new deploitChartData("全年", 0));

            //fdPlanType: 0年计划， 1月计划，20年实际， 30月实际， 40昨日
            foreach (var item in queryBydeploitChart.Rows)
            {
                if (item["fdPlanYear"].ToString().Trim() == string.Empty)
                {
                    continue;
                }
                int dataType = Common.GetIntValue(item["fdPlanType"]);
                int month = Common.GetIntValue(item["fdPlanMonth"]);
                if (month == 0)
                {
                    if (ShowChartYearDataAndTrendLine)
                    {
                        lstData[lstData.Count - 1].PlanValue = Common.GetDecimalValue(item["fdPlanMine"]);
                        lstData[lstData.Count - 1].DataValue = Common.GetDecimalValue(item["fdActualSum"]);
                    }
                }
                else if (month <= currentMonth)
                {
                    lstData[month - 1].PlanValue = Common.GetDecimalValue(item["fdPlanMine"]);
                    lstData[month - 1].DataValue = Common.GetDecimalValue(item["fdActualSum"]);
                }

            }
            itemsSource.Add(lstData);

            if (ShowChartYearDataAndTrendLine)
            {
                for (int i = 0; i < lstRate.Count; i++)
                {
                    lstRate[i].DataValue = Common.GetPercent(lstData[i].DataValue, lstData[i].PlanValue);
                }
                itemsSource.Add(lstRate);
            }

            this.deploitChart.ItemsSource = itemsSource;
        }
        #endregion

        #region  本月所有工作面的原煤产量曲线图

        public void GetCurveChartData(RadChart curveChart ,TextBlock text)
        {
            this.curveChart = curveChart;
            text.Text = "本月各工作面产量";

            EIInfo eiInfo = new EIInfo();
            eiInfo.Set("service", "ZMCA03");
            eiInfo.Set("method", "queryByCurveChart");

            HttpServiceAgent agent = new HttpServiceAgent();
            agent.CallService(eiInfo, getCurveChartDataCompleted);
        }

        private void getCurveChartDataCompleted(object sender, DoWorkCompletedEventArgs e)
        {
            if (e.EIInfo.Status == -1)
            {
                Common.Alert(Common.MsgLoadDataError);
                return;
            }
            EIInfo eiInfo = e.EIInfo;
            EIBlock queryBlock = eiInfo.GetBlock("queryBlock");

            curveChart.SeriesMappings.Clear();
            curveChart.DefaultSeriesDefinition.ShowItemToolTips = true;
            curveChart.DefaultSeriesDefinition.LegendDisplayMode = LegendDisplayMode.DataPointLabel;
            this.curveChart.DefaultView.ChartArea.AxisY.MajorGridLinesVisibility = Visibility.Visible;
            this.curveChart.DefaultView.ChartArea.AxisY.MinorGridLinesVisibility = Visibility.Visible;
            this.curveChart.DefaultView.ChartArea.AxisY.StripLinesVisibility = Visibility.Visible;
            this.curveChart.DefaultView.ChartArea.AxisY.DefaultLabelFormat = Common.ChartDefaultLabelFormat;

            SeriesMapping sm1 = AddBarToCurveChart("计划", 0);
            SeriesMapping sm2 = AddBarToCurveChart("实际", 1);
            sm1.SeriesDefinition.ItemLabelFormat = Common.ChartDefaultLabelFormat;
            sm2.SeriesDefinition.ItemLabelFormat = Common.ChartDefaultLabelFormat;
            curveChart.SeriesMappings.Add(sm1);
            curveChart.SeriesMappings.Add(sm2);

            curveChart.DefaultView.ChartTitle.Content = "本月采煤产量对比";
            curveChart.DefaultView.ChartLegend.Header = "单位：吨" ;
            curveChart.DefaultView.ChartArea.AxisX.LabelRotationAngle = 45;

            this.curveChart.DefaultView.ChartTitle.FontSize = Common.FontsizeSetting + 2;
            this.curveChart.DefaultView.ChartArea.FontSize = Common.FontsizeSetting;
            this.curveChart.DefaultView.ChartLegend.FontSize = Common.FontsizeSetting - 2;
            this.curveChart.DefaultView.ChartArea.AxisY.DefaultLabelFormat = Common.ChartDefaultLabelFormat;

            List<List<ChartData>> itemsSource = new List<List<ChartData>>();
            List<ChartData> lstActual = new List<ChartData>();
            List<ChartData> lstPlan = new List<ChartData>();

            foreach (var item in queryBlock.Rows)
            {
                lstPlan.Add(new ChartData(Common.GetStringValue(item["fdWorkface"]),
                    Common.GetDecimalValue(item["fdPlanMine"])));
                lstActual.Add(new ChartData(Common.GetStringValue(item["fdWorkface"]),
                    Common.GetDecimalValue(item["fdActualSum"])));                                               
            }
            itemsSource.Add(lstPlan);
            itemsSource.Add(lstActual);
            
            curveChart.ItemsSource = itemsSource;
        }

        private  SeriesMapping AddBarToCurveChart(string label, int index)
        {
            SeriesMapping smBar = new SeriesMapping();
            BarSeriesDefinition totalBar = new BarSeriesDefinition();
            totalBar.ShowItemToolTips = true;
            smBar.SeriesDefinition = totalBar;
            smBar.CollectionIndex = index;
            smBar.LegendLabel = label;

            smBar.SeriesDefinition.ShowItemLabels = false;
            smBar.SeriesDefinition.ShowItemToolTips = true;
            smBar.ItemMappings.Add(new ItemMapping("Date", DataPointMember.XCategory));
            smBar.ItemMappings.Add(new ItemMapping("DataValue", DataPointMember.YValue));

            smBar.SeriesDefinition.ShowZeroValuesLabels = true;
            smBar.SeriesDefinition.InteractivitySettings.HoverScope = InteractivityScope.Series;
            smBar.SeriesDefinition.InteractivitySettings.SelectionScope = InteractivityScope.Series;
            smBar.SeriesDefinition.InteractivitySettings.SelectionMode = ChartSelectionMode.Multiple;
            smBar.SeriesDefinition.ItemLabelFormat = Common.ChartItemLabelFormat;
            return smBar;
        }
        #endregion

        #region   采煤日进度曲线图

        public void GetDayChartData(RadChart dayChart)
        {
            this.dayChart = dayChart;

            EIInfo eiInfo = new EIInfo();
            eiInfo.Set("service", "ZMCA03");
            eiInfo.Set("method", "queryByDayChart");

            HttpServiceAgent agent = new HttpServiceAgent();
            agent.CallService(eiInfo, getDayChartDataCompleted);
        }

        public void getDayChartDataCompleted(object sender, DoWorkCompletedEventArgs e)
        {
            if (e.EIInfo.Status == -1)
            {
                Common.Alert(Common.MsgLoadDataError);
                return;
            }
            EIInfo eiInfo = e.EIInfo;
            EIBlock queryPlanDayMine = eiInfo.GetBlock("queryPlanDayMine");
            EIBlock queryActualDayMine = eiInfo.GetBlock("queryActualDayMine");
            int currentMonth = Common.GetIntValue(eiInfo.Get("month"));
            int currentYear = Common.GetIntValue(eiInfo.Get("year"));
            int currentDay = Common.GetIntValue(eiInfo.Get("day"));
            int daysOfCurrentMonth = Common.GetIntValue(eiInfo.Get("daysOfCurrentMonth"));

            dayChart.SeriesMappings.Clear();
            dayChart.DefaultView.ChartTitle.Content = "本月采煤量趋势分析";
            dayChart.DefaultSeriesDefinition.ShowItemToolTips = true;
            dayChart.DefaultSeriesDefinition.LegendDisplayMode = LegendDisplayMode.DataPointLabel;
            dayChart.DefaultView.ChartLegend.Header = string.Empty;
          //  dayChart.DefaultView.ChartLegendPosition = Telerik.Windows.Controls.Dock.Bottom;
            this.dayChart.DefaultView.ChartArea.AxisY.MajorGridLinesVisibility = Visibility.Visible;
            this.dayChart.DefaultView.ChartArea.AxisY.MinorGridLinesVisibility = Visibility.Visible;
            this.dayChart.DefaultView.ChartArea.AxisY.StripLinesVisibility = Visibility.Visible;
            this.dayChart.DefaultView.ChartArea.AxisY.DefaultLabelFormat = Common.ChartDefaultLabelFormat;

            this.dayChart.DefaultView.ChartTitle.FontSize = Common.FontsizeSetting + 2;
            this.dayChart.DefaultView.ChartArea.FontSize = Common.FontsizeSetting;
            this.dayChart.DefaultView.ChartLegend.FontSize = Common.FontsizeSetting - 2;
            this.dayChart.DefaultView.ChartArea.AxisY.DefaultLabelFormat = Common.ChartDefaultLabelFormat;


            String unit = "吨";
            dayChart.DefaultView.ChartLegend.Header = "单位：" + unit;

            SeriesMapping sm1 = Common.GenerateSeriesForChart("计划", 0, "Spline", "PlanValue");
            SeriesMapping sm2 = Common.GenerateSeriesForChart("实际", 0, "Spline");
            sm1.SeriesDefinition.ItemLabelFormat = Common.ChartDefaultLabelFormat;
            sm2.SeriesDefinition.ItemLabelFormat = Common.ChartDefaultLabelFormat;
            dayChart.SeriesMappings.Add(sm1);
            dayChart.SeriesMappings.Add(sm2);

            List<List<ChartData>> itemsSource = new List<List<ChartData>>();
            List<ChartData> lstData = new List<ChartData>();
            List<ChartData> lstActualData = new List<ChartData>();

            for (int i = 1; i <= currentDay;i++ )
            {
                lstData.Add(new ChartData(i + "",0));
            }

            decimal dayPlanValue = Common.GetDecimalValue(queryPlanDayMine.Get(0, "fdPlanMine"));
            foreach(var item in lstData)
            {
                item.PlanValue = dayPlanValue;
            }

            foreach(var item in queryActualDayMine.Rows)
            {
                if(Common.GetStringValue(item["fdPlanMonth"])!= String.Empty)
                {
                    DateTime time = Convert.ToDateTime(Common.GetStringValue(item["fdPlanMonth"]));
                    int day = time.Day;
                  
                    lstData[day-1].DataValue =  Common.GetDecimalValue(item["fdActualSum"]);                }
            }

            itemsSource.Add(lstData);
            dayChart.ItemsSource = itemsSource;
        }

        #endregion

        #region   本月各工程开拓进尺量曲线图
        public void GetDeploitChartDataCurrentMonth(RadChart deploitChart, TextBlock text)
        {
            this.grubChart = deploitChart;
            text.Text = "本月各工程开拓量";

            EIInfo eiInfo = new EIInfo();
            eiInfo.Set("service", "ZMCA03");
            eiInfo.Set("method", "queryByDeploitChartCurrentMonth");

            HttpServiceAgent agent = new HttpServiceAgent();
            agent.CallService(eiInfo, getDeploitChartDataCurrentMonthCompleted);
        }

        private void getDeploitChartDataCurrentMonthCompleted(object sender, DoWorkCompletedEventArgs e)
        {
            if (e.EIInfo.Status == -1)
            {
                Common.Alert(Common.MsgLoadDataError);
                return;
            }
            EIInfo eiInfo = e.EIInfo;
            EIBlock queryBlock = eiInfo.GetBlock("queryBlock");

            grubChart.SeriesMappings.Clear();
            grubChart.DefaultSeriesDefinition.ShowItemToolTips = true;
            grubChart.DefaultSeriesDefinition.LegendDisplayMode = LegendDisplayMode.DataPointLabel;
            this.grubChart.DefaultView.ChartArea.AxisY.MajorGridLinesVisibility = Visibility.Visible;
            this.grubChart.DefaultView.ChartArea.AxisY.MinorGridLinesVisibility = Visibility.Visible;
            this.grubChart.DefaultView.ChartArea.AxisY.StripLinesVisibility = Visibility.Visible;
            this.grubChart.DefaultView.ChartArea.AxisY.DefaultLabelFormat = Common.ChartDefaultLabelFormat;

            SeriesMapping sm1 = AddBarToCurveChart("计划", 0);
            SeriesMapping sm2 = AddBarToCurveChart("实际", 1);
            sm1.SeriesDefinition.ItemLabelFormat = Common.ChartDefaultLabelFormat;
            sm2.SeriesDefinition.ItemLabelFormat = Common.ChartDefaultLabelFormat;
            grubChart.SeriesMappings.Add(sm1);
            grubChart.SeriesMappings.Add(sm2);

            grubChart.DefaultView.ChartTitle.Content = "本月掘进进尺对比";
            grubChart.DefaultView.ChartLegend.Header = "单位：米";
            grubChart.DefaultView.ChartArea.AxisX.LabelRotationAngle = 45;
            this.grubChart.DefaultView.ChartTitle.FontSize = Common.FontsizeSetting + 2;
            this.grubChart.DefaultView.ChartArea.FontSize = Common.FontsizeSetting;
            this.grubChart.DefaultView.ChartLegend.FontSize = Common.FontsizeSetting - 2;
            this.grubChart.DefaultView.ChartArea.AxisY.DefaultLabelFormat = Common.ChartDefaultLabelFormat;


            List<List<ChartData>> itemsSource = new List<List<ChartData>>();
            List<ChartData> lstActual = new List<ChartData>();
            List<ChartData> lstPlan = new List<ChartData>();

            foreach (var item in queryBlock.Rows)
            {
                lstPlan.Add(new ChartData(Common.GetStringValue(item["fdProjectId"]),
                    Common.GetDecimalValue(item["fdPlanMine"])));
                lstActual.Add(new ChartData(Common.GetStringValue(item["fdProjectId"]),
                    Common.GetDecimalValue(item["fdActualSum"])));
            }
            itemsSource.Add(lstPlan);
            itemsSource.Add(lstActual);
           
            grubChart.ItemsSource = itemsSource;

        }
        #endregion

        #region   掘进日进度曲线
        public void GetDayGrubChartData(RadChart chart)
        {
            this.grubDayChart = chart;

            EIInfo eiInfo = new EIInfo();
            eiInfo.Set("service", "ZMCA03");
            eiInfo.Set("method", "queryByDayGrubChart");

            HttpServiceAgent agent = new HttpServiceAgent();
            agent.CallService(eiInfo, getGrubDayChartDataCompleted);
        }

        private void getGrubDayChartDataCompleted(object sender, DoWorkCompletedEventArgs e)
        {
            if (e.EIInfo.Status == -1)
            {
                Common.Alert(Common.MsgLoadDataError);
                return;
            }

            EIInfo eiInfo = e.EIInfo;
            EIBlock queryPlanDayGrub = eiInfo.GetBlock("queryPlanDayGrub");
            EIBlock queryActualDayGrub = eiInfo.GetBlock("queryActualDayGrub");
            int currentMonth = Common.GetIntValue(eiInfo.Get("month"));
            int currentYear = Common.GetIntValue(eiInfo.Get("year"));
            int currentDay = Common.GetIntValue(eiInfo.Get("day"));
            int daysOfCurrentMonth = Common.GetIntValue(eiInfo.Get("daysOfCurrentMonth"));
            string unit = "米";
            grubDayChart.SeriesMappings.Clear();
            grubDayChart.DefaultView.ChartTitle.Content = "本月掘进量趋势分析";
            grubDayChart.DefaultSeriesDefinition.ShowItemToolTips = true;
            grubDayChart.DefaultSeriesDefinition.LegendDisplayMode = LegendDisplayMode.DataPointLabel;
            grubDayChart.DefaultView.ChartLegend.Header = string.Empty;
         //   grubDayChart.DefaultView.ChartLegendPosition = Telerik.Windows.Controls.Dock.Bottom;

            this.grubDayChart.DefaultView.ChartTitle.FontSize = Common.FontsizeSetting + 2;
            this.grubDayChart.DefaultView.ChartArea.FontSize = Common.FontsizeSetting;
            this.grubDayChart.DefaultView.ChartLegend.FontSize = Common.FontsizeSetting - 2;
            this.grubDayChart.DefaultView.ChartArea.AxisY.DefaultLabelFormat = Common.ChartDefaultLabelFormat;

            grubDayChart.DefaultView.ChartLegend.Header = "单位：" + unit;

            SeriesMapping sm1 = Common.GenerateSeriesForChart("计划", 0, "Spline", "PlanValue");
            SeriesMapping sm2 = Common.GenerateSeriesForChart("实际", 0, "Spline");
            sm1.SeriesDefinition.ItemLabelFormat = Common.ChartDefaultLabelFormat;
            sm2.SeriesDefinition.ItemLabelFormat = Common.ChartDefaultLabelFormat;
            grubDayChart.SeriesMappings.Add(sm1);
            grubDayChart.SeriesMappings.Add(sm2);

            List<List<ChartData>> itemsSource = new List<List<ChartData>>();
            List<ChartData> lstData = new List<ChartData>();
            List<ChartData> lstActualData = new List<ChartData>();

            for (int i = 1; i <= currentDay; i++)
            {
                lstData.Add(new ChartData(i + "", 0));
            }

            decimal dayPlanValue = Common.GetDecimalValue(queryPlanDayGrub.Get(0, "fdPlanGrub"));
            foreach (var item in lstData)
            {
                item.PlanValue = dayPlanValue;
            }

            foreach (var item in queryActualDayGrub.Rows)
            {
                if (Common.GetStringValue(item["fdPlanMonth"]) != String.Empty)
                {
                    DateTime time = Convert.ToDateTime(Common.GetStringValue(item["fdPlanMonth"]));
                    int day = time.Day;
                    lstData[day-1].DataValue = Common.GetDecimalValue(item["fdActualSum"]);
                }
            }

            itemsSource.Add(lstData);
            grubDayChart.ItemsSource = itemsSource;
        }

        #endregion
    }

}
